package com.itcat.controller;

import com.itcat.common.CommonPage;
import com.itcat.common.CommonResult;
import com.itcat.mysql.pojo.UmsMenu;
import com.itcat.mysql.pojo.UmsRole;
import com.itcat.mysql.vo.UsmMenuVo;
import com.itcat.service.UsmMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * [一句话描述该类的功能]
 *
 * @author : [Cr Mr]
 * @version : [v1.0]
 * @date : [2022/4/3 8:53]
 */
@RestController
@RequestMapping("/menu")
public class UsmMenuContrller {

    @Autowired
    private UsmMenuService usmMenuService;

    /***
     * 树形结构返回所有菜单列表
     * @author Cr Mr
     * @date 2022/4/3 8:55
     */
    @GetMapping("treeList")
    public CommonResult treeList() {
        List<UsmMenuVo> list = usmMenuService.treeList();
        return CommonResult.success(list);
    }

    /***
     * 分页查询后台菜单
     * @author Cr Mr
     * @date 2022/4/3 16:06
     */
    @GetMapping("list/{parentId}")
    public CommonResult list(@PathVariable Long parentId,
                             @RequestParam(required = false) Integer pageNum,
                             @RequestParam(required = false) Integer pageSize) {
        CommonPage<UmsMenu> page = usmMenuService.list(parentId, pageNum, pageSize);
        return CommonResult.success(page);
    }

    /***
     * 添加角色
     * @author Cr Mr
     * @date 2022/4/3 10:33
     */
    @PostMapping("create")
    public CommonResult create(@RequestBody UmsMenu umsMenu) {
        usmMenuService.create(umsMenu);
        return CommonResult.success();
    }

    /***
     * 根据ID删除后台菜单
     * @author Cr Mr
     * @date 2022/4/3 16:32
     */
    @PostMapping("delete/{id}")
    public CommonResult delete(@PathVariable Long id) {
        usmMenuService.delete(id);
        return CommonResult.success();
    }

    /***
     * 修改后台菜单
     * @author Cr Mr
     * @date 2022/4/3 16:53
     */
    @PostMapping("update/{id}")
    public CommonResult update(@PathVariable Long id, @RequestBody UmsMenu umsMenu) {
        usmMenuService.update(id, umsMenu);
        return CommonResult.success();
    }

    /***
     * 修改菜单显示状态
     * @author Cr Mr
     * @date 2022/4/3 17:01
     */
    @PostMapping("updateHidden/{id}")
    public CommonResult updateHidden(@PathVariable Long id, @RequestParam Integer hidden) {
        usmMenuService.updateHidden(id, hidden);
        return CommonResult.success();
    }

    /***
     * 根据ID获取菜单详情
     * @author Cr Mr
     * @date 2022/4/3 17:04
     */
    @GetMapping("/{id}")
    public CommonResult getUmsMenu(@PathVariable Long id) {
        UmsMenu umsMenu = usmMenuService.getUmsMenu(id);
        return CommonResult.success(umsMenu);
    }
}
